<!doctype html>
<html>
<head>
    <meta charset="UTF-8">
    <title></title>
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
    <link href="../../libs/mui.min.css" rel="stylesheet"/>
    <link href="../../css/main.css" rel="stylesheet"/>
    <link rel="stylesheet" href="../../css/main-assess.css"/>
</head>

<body>
<div class="head">
    <img class="mui-action-back" id="back" src="../../images/all-left.png" alt="">
    <p>我的贷款评估</p>
</div>

<div class="title">
    <div class="active"><span>通过</span></div>
    <div><span>未通过</span></div>
</div>

<div class="content-f content" id="content-f">
    <p class="content-f-num">贷款评估通过<span class="times"></span>条</p>

    <!--<div class="content-f-fi">
        <p class="content-f-fi-title">人寿保单评估</p>
        <div class="content-f-name">
            <span>申请人：张三</span><span>评估记录：通过</span>
        </div>
        <div class="content-f-money">
            <span>可申请金额：10，000元～15，000元</span>
        </div>
    </div>-->

</div>

<div class="content-s content" id="content-s" style="display: none;">
    <p class="content-f-num">贷款评估未通过<span class="times"></span>条</p>
    <!--<div class="content-f-fi">
        <p class="content-f-fi-title">人寿保单评估</p>
        <div class="content-f-name">
            <span>申请人：张三</span><span>评估记录：未通过</span>
        </div>
        <div class="content-f-money">
            <span>可申请金额：10，000元～15，000元</span>
        </div>
    </div>-->
</div>
<p class="more"></p>
<script src="../../js/jquery-3.1.1.min.js"></script>
<script src="../../libs/mui.min.js"></script>
<script src="../../js/url.js"></script>
<script>
    //  数据请求
    var state1 = new Assess('', '#content-f', 1);
    var state2 = new Assess('未', '#content-s', 1);
    state1.getAssess();
    function Assess(f, content, page) {
        this.page = page;
        this.f = f;
        this.content = content;
        var self = this;
        this.getAssess = function () {
            var state = true;
            if (this.f != '') {
                state = !state
            }
            ;
            $.ajax({
                url: ur + 'rest/loanController/getEvaluate',
                type: "get",
                dataType: 'json',
                headers: {
                    "X-Token": localStorage.token
                },
                data: {
                    succ: state,
                    page: self.page,
                },
                success: function (data) {
                    if (data.meta.code === 'S002') {
                        var n = data.data.list.length;
                        var totalPage = Math.ceil(data.data.total / 10)
                        var itemL = $(self.content + '>.content-f-fi').length;
                        if (itemL === 0 || itemL != n && itemL != 0) {
                            for (var i = 0; i < n; i++) {
                                var div = $('<div class="content-f-fi">' +
                                    '<p class="content-f-fi-title">' + data.data.list[i].loan + '</p>' +
                                    '<div class="content-f-name">' + '<span>申请人:' + data.data.list[i].user + '</span>' +
                                    '<span>评估记录：' + self.f + '通过' + '</span>' +
                                    '</div>' +
                                    '<div class="content-f-money">' +
                                    '<p>可申请金额：<span class="apply-money">' + data.data.list[i].price + '</span>万元</p>' +
                                    '</div>' + '</div>');
                                if (f == '未') {
                                    $('#content-s').append(div);
                                } else {
                                    $('#content-f').append(div)
                                }
                            }
                        }
                        $('.times').text(data.data.total);
                        $('.more').text('点击加载更多');
                        if (data.data.total > n) {
                            $('.more').on('tap', function () {
                                if (self.page < totalPage) {
                                    self.page++;
                                    new Assess(self.f, self.content, self.page).getAssess();
                                } else {
                                    $('.more').text('您已没有更多评估！');
                                }
                            })
                        } else if (n != 10) {
                            $('.more').text('')
                        }
                    } else {
                        mui.toast(data.meta.message);
                    }
                }
            })
        }
    }
    //	切换
    $('.title>div').on('tap', function () {
        $(this).attr('class', 'active');
        $(this).siblings().removeClass('active');
        if ($(this).index() == 0) {
            $('.content-f').css('display', 'block')
            $('.content-s').css('display', 'none')
            state1.getAssess();
        } else {
            $('.content-f').css('display', 'none')
            $('.content-s').css('display', 'block')
            state2.getAssess()
        }
    })

    //跳转
    $('.content').on('tap', '.content-f-fi', function () {
        localStorage.rs = $(this).find('.apply-money').text();
        localStorage.thisWebId = 'mine-assess';
        $(this).parent().attr('id') === 'content-f' ? localStorage.assess = 'pass' : localStorage.assess = 'fail';
        localStorage.setItem('assess-evaluate', 'assess-evaluate');
        href('../home/evaluate.html', 'evaluate.html');
    })

</script>
</body>
</html>